home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / D51_NUSource / Source / Routines / ARexx.s next >
Text File  |  1995-08-20  |  9KB  |  234 lines

  1. *= Create NudelRexxMsg (NORMAL) =**************************************= 11-Aug-1995 =*
  2. *  Inputs: CRexxPort(a5) - Ptr to null-term, case-sensitive name of host to talk to.  *
  3. *          NudelPort(a5) - Ptr to our MsgPort.                          *
  4. * Outputs: NudelRexxMsg(a5) - Ptr to our RexxMsg structure.                  *
  5. ***************************************************************************************
  6. CreateNudelRexxMsg
  7.     Tst.l    NudelPort(a5)            -._ If our port hasn't been created yet
  8.     Beq    Internal            -'  generate "Internal" error.
  9.     Tst.l    CRexxPort(a5)            -._ Make sure the port to talk to
  10.     Beq    Internal            -'  has been defined, else "internal".
  11.  
  12.     Move.w    #0,a1                Use default extension ".REXX"
  13.     Move.l    CRexxPort(a5),d0        Port we want to talk to.
  14.     Move.l    NudelPort(a5),a0        Our MsgPort.
  15.     N_CallRexSysLib    CreateRexxMsg
  16.     Move.l    d0,NudelRexxMsg(a5)
  17.     Beq_ErrorE    ErrAct_CreateRexxMsg(pc),#0
  18.     RTS
  19.  
  20. ErrAct_CreateRexxMsg
  21.     Dc.b    "Could not create RexxMsg",0
  22.     Even
  23.  
  24. *= Delete NudelRexxMsg (NORMAL) =**************************************= 11-Aug-1995 =*
  25. *  Inputs: NudelRexxMsg(a5) - Ptr to our RexxMsg structure.                  *
  26. * Outputs: NudelRexxMsg(a5) - Null.                              *
  27. *=====================================================================================*
  28. *   Notes: This routine also clears/frees all argument pointers.              *
  29. ***************************************************************************************
  30. DeleteNudelRexxMsg
  31.     Tst.l    NudelRexxMsg(a5)        -._ Skip routine if there
  32.     Beq.s    DeleteNudelRexxMsg_Skip        -'  is no RexxMsg structure.
  33.     Bsr.s    ClearNudelRexxMsg        Clear argument pointers, if any.
  34.     Move.l    NudelRexxMsg(a5),a0        RexxMsg to a0 for Deletion
  35.     N_JumpRexSysLib    DeleteRexxMsg        Delete it.
  36. ;;;;;;;    RTS for us.
  37. DeleteNudelRexxMsg_Skip
  38.     RTS
  39.  
  40. *= Clear NudelRexxMsg (NORMAL) =***************************************= 12-Aug-1995 =*
  41. *  Inputs: NudelRexxMsg(a5) - Ptr to our RexxMsg structure.                  *
  42. * Outputs: NudelRexxMsg(a5)->rm_Args - all cleared.                      *
  43. *=====================================================================================*
  44. *   Notes: This routine will count the number of arguments to clear automatically.    *
  45. *          Does not support empty arguments in-between filled ones (nor does ARexx).  *
  46. ***************************************************************************************
  47. ClearNudelRexxMsg
  48.     Tst.l    NudelRexxMsg(a5)        -._ Skip routine if there
  49.     Beq.s    ClearNudelRexxMsg_Skip2        -'  is no RexxMsg structure.
  50.  
  51.     Move.l    NudelRexxMsg(a5),a0        Point to RexxMsg
  52.     Tst.l    rm_Result2(a0)            -._ If there is no result
  53.     Beq.s    ClearNudelRexxMsg_Skip1        -'  string to clear, skip.
  54.     Move.l    rm_Result2(a0),a0        ArgString -> a0 for DeleteArgString()
  55.     N_CallRexSysLib    DeleteArgstring        Free the rm_Result2 string.
  56. ClearNudelRexxMsg_Skip1
  57.     Move.l    NudelRexxMsg(a5),a0        -._ Ensure rm_Result2 now
  58.     Move.l    #0,rm_Result2(a0)        -'  has a NULL pointer.
  59.  
  60. ;;;;;;;    Move.l    NudelRexxMsg(a5),a0        -._ Point to
  61.     Lea    rm_Args(a0),a0            -'  RexxMsg->rm_Args
  62.     Moveq    #-1,d0                d0 counts how many args to clear.
  63.     Moveq    #MAXRMARG-1,d7            Maximum number of args to loop counter.
  64. ;;;;;;; d0,d7 adjusted for DBxx loop entered from the top.
  65.  
  66. CNRMCnt    Addq.l    #1,d0                Increment number of args.
  67.     Tst.l    (a0)+                Another argument?
  68.     DBeq    d7,CNRMCnt                Count them all.
  69.  
  70.     Tst.l    d0                -._ If nothing to clear,
  71.     Beq.s    ClearNudelRexxMsg_Skip2        -'  skip the rest of it.
  72.  
  73. ;;;;;;;    Move.l    d0,d0                Count into d0
  74.     Move.l    NudelRexxMsg(a5),a0        RexxMsg to a0
  75.     N_JumpRexSysLib    ClearRexxMsg        Clear all the arguments.
  76. ;;;;;;;    RTS for us.
  77. ClearNudelRexxMsg_Skip2
  78.     RTS
  79.  
  80. *= Fill NudelRexxMsg (NORMAL) =****************************************= 11-Aug-1995 =*
  81. *  Inputs: NudelRexxMsg(a5) - Ptr to our RexxMsg structure.                  *
  82. *          a1 - Ptr to Null-term, case sensitive command to put into 1st argument.    *
  83. * Outputs: NudelRexxMsg(a5)->rm_Args[1] - Filled in argument.                  *
  84. *          NudelRexxMsg(a5)->rm_Action - "String-file" bit set, rest cleared.          *
  85. *=====================================================================================*
  86. *   Notes: This routine is _only_ for inserting a single-argument "string-file"       *
  87. *          No checking is done to ensure that (a1) is valid.                  *
  88. ***************************************************************************************
  89. FillNudelRexxMsg
  90.     Move.l    a1,-(SP)        Preserve a1
  91.     Tst.l    NudelRexxMsg(a5)    -._ If no previous RexxMsg structure,
  92.     Beq.s    FNRM_Skp        -'  don't try and free it! :-).
  93.     Bsr.s    DeleteNudelRexxMsg    Delete the used RexxMsg (can't re-use)
  94. FNRM_Skp
  95.     Bsr    CreateNudelRexxMsg    Create a new RexxMsg structure.
  96.  
  97.     Bsr.s    ClearNudelRexxMsg    Clear it first.
  98.     Move.l    (SP)+,a1
  99.     Move.l    NudelRexxMsg(a5),a0    RexxMsg
  100.     Move.l    #RXCOMM!RXFF_STRING!RXFF_RESULT,rm_Action(a0)
  101. ;        Command, "string-file", results
  102.     Move.l    a1,rm_Args(a0)        Argument
  103.     Moveq    #1,d0            Just one message.
  104.     Moveq    #0,d1            All args are strings.
  105.     N_CallRexSysLib    FillRexxMsg    Fill in argument.
  106.     Tst.l    d0
  107.     Beq_ErrorE    ErrAct_FillRexxMsg(pc),#0
  108.     RTS
  109.  
  110. ErrAct_FillRexxMsg
  111.     Dc.b    "Could not fill RexxMsg",0
  112.     Even
  113.  
  114.  
  115. *= Send NudelRexxMsg (NORMAL) =****************************************= 16-Aug-1995 =*
  116. *  Inputs: NudelRexxMsg(a5) - Fully filled-in RexxMsg for sending.              *
  117. *          CRexxPort(a5) - Ptr to null-term, case sensitive name of port to send to.  *
  118. * Outputs: NudelRexxMsg(a5)->Result1 - RC, the numerical return code.              *
  119. *          NudelRexxMsg(a5)->Result2 - RESULT - Ptr to null-term ASCII result string. *
  120. *=====================================================================================*
  121. *   Notes: Assumes the first real msg received is a reply to the one it sends out,    *
  122. *          and will send out warnings if this is not the case.                  *
  123. *        : If Result2 is returned it must be freed (done by our Clear routine).          *
  124. ***************************************************************************************
  125. FillAndSendNudelRexxMsg
  126.     Bsr.s    FillNudelRexxMsg
  127. ;;;;;;;    Bra.s    SendNudelRexxMsg
  128.  
  129. SendNudelRexxMsg
  130.     Bsr    CkCtrlC            Check for ^C-Break and quit if sent.
  131.  
  132.     N_CallExec    Forbid        Forbid multitasking.
  133. ;                    Ensures port doesn't close.
  134.     Move.l    CRexxPort(a5),a1    Name of host port to send to.
  135.     N_CallExec    FindPort    Find the port.
  136.     Tst.l    d0            -._ If the port doesn't exist,
  137.     IFND    Beta_Version_ARexx
  138.     Beq.s    FindPort_NOT        -'  Permit() and call Error
  139.     ELSE
  140.     Beq    FindPort_NOT        -'  Permit() and call Error
  141.     ENDC
  142.  
  143.     Move.l    d0,a0            Port to a0 for PutMsg()
  144.     Move.l    NudelRexxMsg(a5),a1    RexxMsg to a1 for PutMsg()
  145.     N_CallExec    PutMsg        Send RexxMsg to the Port.
  146.     N_CallExec    Permit        Permit multitasking.
  147.  
  148. SNM_WP_Loop
  149.     Move.l    NudelPort(a5),a0    -._ Wait for a msg
  150.     N_CallExec    WaitPort    -'  to our port.
  151.  
  152.     Move.l    NudelPort(a5),a0    -._ Get the message
  153.     N_CallExec    GetMsg        -'  sent to us.
  154.     Tst.l    d0            -._ If there wasn't really
  155.     Beq.s    SNM_WP_Loop        -'  a message, wait again.
  156.  
  157.     Move.l    d0,-(SP)        Preserve d0
  158.  
  159.     Move.l    NudelRexxMsg(a5),d1            -.
  160.     Cmp.l    d0,d1                     |- Warning if this msg isn't
  161.     Bsrne_ErrorW    ErrAct_NotOurMsg(pc),#0        -'  the same one we sent out.
  162.  
  163.     Move.l    (SP),a0                    -.
  164.     Cmpi.b    #NT_REPLYMSG,LN_TYPE(a0)         |- Warning if this isn't
  165.     Bsrne_ErrorW    ErrAct_NotReplyMsg(pc),#0    -'  a reply.
  166.  
  167.     Move.l    (SP)+,d0        Restore d0 and SP.
  168.  
  169.     IFD    Beta_Version_ARexx        Output debug-requester for Beta-Versions
  170.     Move.l    d0,-(SP)
  171.  
  172.     Move.l    d0,a0                -.
  173.     Move.l    CRexxPort(a5),RDF_1_Long(a5)     |
  174.     Move.l    rm_Args(a0),RDF_2_Long(a5)     |- Setup data array
  175.     Move.l    rm_Result1(a0),RDF_3_Long(a5)     |  for RawDoFmt()
  176.     Move.l    rm_Result2(a0),RDF_4_Long(a5)    -'
  177.  
  178.     Lea    RDF_Result_Input(pc),a0        Input string.
  179.     Lea    RDF_Array(a5),a1        DataArray
  180.     Lea    BufferA(a5),a3            -._ Output Buffer
  181.     Move.l    a3,RDF_Adrs(a5)            -'  (Only when Beta_Version_ARexx)
  182.     Move.l    #BufferALen,RDF_Size(a5)    Size of output buffer.
  183.     Bsr    NudelRawDoFmt
  184.  
  185.  
  186.     Move.l    #N_EasyStruct_Len,N_ES_Length(a5)    Size of structure.
  187.     Move.l    #0,N_ES_Flags(a5)            No flags.
  188.     Lea    ErrReq_Title(pc),a0        -.
  189.     Move.l    a0,N_ES_Title(a5)         |
  190.     Lea    BufferA(a5),a0             |_ Texts for
  191.     Move.l    a0,N_ES_Body(a5)         |  requester.
  192.     Lea    ErrReq_Gads(pc),a0         |
  193.     Move.l    a0,N_ES_Gadgets(a5)        -'
  194.  
  195.     Lea    N_EasyStruct(a5),a1    Point to EasyRequest structure.
  196.     Sub.l    a0,a0            Specify default public screen.
  197.     Move.l    a0,a2            No IDCMP flags.
  198.     Move.l    a0,a3            No arguments.
  199.     N_CallInt    EasyRequestArgs    Put up the request.
  200.  
  201.     Move.l    (SP)+,d0
  202.     ENDC
  203.  
  204.     RTS                Done.
  205.  
  206.     IFD    Beta_Version_ARexx
  207.  
  208. RDF_Result_Input
  209.     Dc.b    "Results of ARexx command:",10
  210.     Dc.b    10
  211.     Dc.b    "Port: '%s'",10
  212.     Dc.b    "Command: '%s'",10
  213.     Dc.b    10
  214.     Dc.b    "RC: %ld",10
  215.     Dc.b    "Result: '%s'"
  216.     Dc.b    0
  217.     Even
  218.     ENDC
  219.  
  220. FindPort_NOT
  221.     N_CallExec    Permit        Permit multitasking.
  222.     Move.l    CRexxPort(a5),NIB_NameAdrs+FakeNIB(a5)    Set pseudo-filename.
  223.     Bra_ErrorE    ErrAct_FindPort(pc),FakeNIB_Adrs(a5)    Fatal error.
  224.  
  225. ErrAct_FindPort
  226.     Dc.b    "Could not find port ",0
  227.     Even
  228.  
  229. ErrAct_NotOurMsg
  230.     Dc.b    "Received message not ours - please report to Leo",0
  231. ErrAct_NotReplyMsg
  232.     Dc.b    "Received message not a reply - please report to Leo",0
  233.     Even
  234.